package com.cy.pj.arithmetic.common.web;

import com.cy.pj.arithmetic.common.exception.ServiceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler({ArrayIndexOutOfBoundsException.class})
    public String doHandleArrayIndexOutOfBoundsException(ArrayIndexOutOfBoundsException e){
        return "数组下标越界";
    }

    @ExceptionHandler(ArithmeticException.class)
    public String doHandleArithmeticException(ArithmeticException e){
        e.printStackTrace();
        return  "计算过程中出现了异常，异常信息为"+e.getMessage();
    }

    @ExceptionHandler(ServiceException.class)
    public String doHandleArithmeticException(ServiceException e){
        e.printStackTrace();
        return "计算过程中出现了异常，异常信息为"+e.getMessage();
    }

    @ExceptionHandler({Throwable.class})
    public String doHandleRuntimeException(Throwable e){//此方法为异常处理的兜底方法
        e.printStackTrace();
        //log.error(...);
        //给运维人员发短信
        //发运维人员发email
        //播放一段音乐(报警)
        return "系统维护中";
    }
}
